package com.hotel.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hotel.entity.Livein;
import com.hotel.entity.RoomInfo;
import com.hotel.entity.RoomState;
import com.hotel.service.RoomService;

@Controller
public class RoomController {
	@Autowired
	private RoomService roomInfoService;

	@RequestMapping(value = "roomlist")
	@ResponseBody
	public ModelAndView getRoomList(HttpServletRequest request, Integer stateId,
			@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
			@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
		ModelAndView mv = new ModelAndView();
		if (stateId != null && stateId == 0) {
			stateId = null;
		}
		List<RoomInfo> room = findRooms(stateId, pageNo, pageSize);
		List<RoomState> roomStateList = roomInfoService.getStateList();
		mv.addObject("room", room);
		mv.addObject("roomStateList", roomStateList);
		mv.addObject("pageNo", pageNo);
		mv.addObject("pageSize", pageSize);
		mv.addObject("stateId", stateId);
		mv.setViewName("views/room/roomseach");
		System.out.println("状态" + roomStateList.size());
		System.out.println("房间信息表" + room.size());
		return mv;
	}

	@RequestMapping(value = "findRooms")
	@ResponseBody
	public List<RoomInfo> findRooms(Integer stateId, @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
			@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
		return roomInfoService.getListByStatu(stateId, pageNo, pageSize);
	}

	@RequestMapping(value = "findByRoomId")
	@ResponseBody
	public RoomInfo findByRoomId(Integer roomId) {
		RoomInfo roomInfo = roomInfoService.findByRoomId(roomId);
		return roomInfo;
	}
	
	@RequestMapping(value = "roomInfoList")
	public ModelAndView roomInfoList(@RequestParam(value="pageNo",defaultValue="1")Integer pageNo,@RequestParam(value="pageSize",defaultValue="10")Integer pageSize){
		ModelAndView mv = new ModelAndView();
		List<RoomInfo> roomInfos = roomInfoService.findRoomInfoList(pageNo,pageSize);
		mv.addObject("roomInfos",roomInfos);
		mv.addObject("pageNo", pageNo);
		mv.addObject("pageSize", pageSize);
		mv.setViewName("views/room/roominfo");
		return mv;
		
	}

	
	

}
